package com.tianji.learning.controller;


import cn.hutool.core.bean.BeanUtil;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.ReplyDTO;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.domain.query.ReplyPageQuery;
import com.tianji.api.vo.ReplyVO;
import com.tianji.learning.service.IInteractionReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动问题的回答或评论 前端控制器
 * </p>
 *
 * @author whx
 * @since 2024-12-03
 */
@RestController
@RequestMapping("/replies")
@Api(tags = "评论相关接口")
public class InteractionReplyController {

    @Autowired
    private IInteractionReplyService interactionReplyService;

    @GetMapping("/page")
    @ApiOperation("分页查询回答与评论列表")
    public PageDTO<ReplyVO> pageReplies(ReplyPageQuery replyPageQuery){
        return interactionReplyService.pageReplies(replyPageQuery);
    }

    @PostMapping
    @ApiOperation("新增回答或评论")
    public void addReply(@RequestBody ReplyDTO dto){
        interactionReplyService.addReply(dto);
    }

    @GetMapping("/{id}")
    public ReplyVO getIRById(@PathVariable Long id){
        InteractionReply bean = interactionReplyService.getById(id);
        return BeanUtil.toBean(bean, ReplyVO.class);
    }

}
